/**
 * 解析URL参数
 * @example ?id=12345&a=b
 * @return Object {id:12345, a:b}
 **/

export const urlParse = () => {
    //url参数解析成json对象
    let url = window.location.search;
    console.log('解析url参数  ' +url);
    let obj = {};
    //通过正则表达式进行解析
    let reg = /[?&][^?g]+=[^?g]+/g;
    let arr = url.match(reg);
    console.log(arr); //['?id=12345',[&a=b]]
    if(arr) {
        arr.forEach(item => {
            let tempArr = item.substring(1).split('=');
            // let key = tempArr[0];
            // let value = tempArr[1];
            let key = decodeURIComponent(tempArr[0]);
            let value = decodeURIComponent(tempArr[1]);
            obj[key] = value; //对象存入数据
        });
        return obj;
    }else {
       //如果地址栏不存在参数,默认参数
       return {id:12345}  
    }
}